//
//  HelpController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/11/1.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "HelpController.h"
#import "QuestionAnswerController.h"
#import "FeedbackModel.h"
#import "FeedbackController.h"

@interface HelpController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableview;

@property (nonatomic , strong)NSMutableArray * array;

@end

@implementation HelpController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)setNavi
{
    self.title = @"帮助";
}

-(void)setUI
{
    self.view.backgroundColor = Color(245, 245, 245);
    self.tableview.backgroundColor = Color(245, 245, 245);
    self.tableview.tableFooterView = [UIView new];
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}

-(void)setData
{
    self.array = [NSMutableArray array];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@help-center/index",BaseUrl] para:nil success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            for (int i = 0 ; i < [[responseObject objectForKey:@"data"] count] ; i ++) {
                FeedbackModel * model = [[FeedbackModel alloc]init];
                [model setValuesForKeysWithDictionary:[responseObject objectForKey:@"data"][i]];
                [self.array addObject:model];
            }
            [self.tableview reloadData];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.textColor = TextAssistColor;
    cell.textLabel.font = FontSize(14);
    FeedbackModel * model  = self.array[indexPath.row];
    cell.textLabel.text = model.help_category_name;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    QuestionAnswerController * vc = [[QuestionAnswerController alloc]init];
    FeedbackModel * model  = self.array[indexPath.row];
    vc.categoryID = model.help_category_id;
    [self.navigationController pushViewController:vc animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}

- (IBAction)feedbackAction:(id)sender {
    
    FeedbackController * vc = [[FeedbackController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
